from button.button import MyControl
import pygame


class Button(MyControl):
    def __init__(self, btn_name, event_id, rect, img_file, img_cx, text, font_info):
        MyControl.__init__(self, rect, img_file, img_cx, text, font_info)

        self.event_id = event_id
        self.name = btn_name

        if self.label is not None:
            x = rect.left + int(rect.width / 2)
            y = rect.top + int(rect.height / 2)
            self.label.set_pos(x, y, 1, 1)

        self.status = 1

    def set_text(self, text):
        self.label.set_text(text)

    def update(self, event):
        if self.check_click(event):
            data = {"from_ui": self.name, "status": self.status}
            ev = pygame.event.Event(self.event_id, data)
            pygame.event.post(ev)
